Pygame 2 Advanced Bonus Tips (including classes, variables, and logic used to help FCA student Teddy Peers make Lost Manor example game) login for http://www.expertmultimedia.com/usingpython/materials/ is user:fca password:password ToDo (high-pri): -change instances of backslashes to use os.path.join instead (requires: import os) so program works on different operating systems: so change things like: bg_image=pygame.image.load(".\\Bin\\World map\\Floor 1\\PNG\\Black white floor 6.png") to things like: bg_image=pygame.image.load( os.path.join('Bin','World map','Floor 1','PNG','Black white floor 6.png") ) -change .convert() to .convert_alpha() (only for sprites) so that transparency works -make another image, like hitmap_image for hit detection & load the black&white image into that (you don't need a surface since you aren't drawing it). Then to determine whether you can move to a certain pixel, set xTest, yTest then, before the moving function, do: if (hitmap_image.get_at((xTest,yTest))==colorWhite): #double parenthesis above are required since get_at accepts 1 ordered pair (a type of variable called a tuple) not two separate integers. Putting parenthesis around a comma-separated list makes them into a tuple. #optionally (to prevent getting stuck) you'd have to define & program a GetNearestBlack function then use it now: #else: # nearestblack=GetNearestBlack(p1.rect.x,p1.rect.y,hitmap_surf) # p1.rect.x=nearestblack.x # p1.rect.y=nearestblack.y # an easier alternative to creating a GetNearestBlack method would be to kick the character back 1 pixel (opposite of direction they are pressing, but if they could somehow first get inside the wall, they would have a backward passing through wall glitch allowing them to go the rest of the way through). ToDo (optional): -change K_KEFT, K_DOWN, K_RIGHT & K_UP to K_a, K_s, K_d & K_w -display text like this : #(at beginning of program): bShowMsg=False sMsg="Hello" font = pygame.font.Font(None, 36) #(every frame): if bShowMsg: antialias=1 colorDarkGray=(10, 10, 10) text = font.render(sMsg, antialias, colorDarkGray) textpos = text.get_rect() textpos.centerx = screen.get_rect().centerx textpos.centery = screen.get_rect().centery screen.blit(text, textpos) ToDo (low-pri): -To avoid missing file errors due to case, change all data folders and filenames to lowercase to avoid operating system issues, then also change code to reflect that -Add exception handling (try searching the internet for pygame exception handling) -Make sure your game saves&loads, at least high scores. This will make your game more exciting and add to replay value. Consider making a subfolder called "saves" and under that, each folder is a saved game. That would be easiest, since then, each character's saved data could be in a separate file, and the player's progress in the game could be another file, and you could even save the state of each area or level each in separate a file for each one if you want to keep track of things like destructible objects, or unlocked doors. You could also make a file for items and store there whether an item -For walk frames, make a list of surfaces, & load them in onload. Then during UpdateFrame surf can be set to one of those e.g. self.surf=self.surfaces[sequencenow*Iwalkframes+Iwalkframe] instead of having to load the file each frame (that math inside the brackets can only get the right frame if each sequence has the same #of frames AND if Iwalkframe starts at 0 instead of 1. For standing still, just copy the standing surface Iwalkframes times) -set clock.tick to 60 to lock to 60fps (pygame clock automatically counts ticks [milliseconds] since last frame). -rewrite frame advancement to use time instead of frames e.g. TickLastStep=pygame.time.get_ticks() then rewrite 'if' case around frame loading to reflect that -change the onload method to accept another parameter that sets the Name so that any character can be loaded into a Player class (including NPCs). -Make an list of Player objects for NPCs (and enemies): players = [] players.append(Player()) players[0].Name="Otherguy" players[0].onload() Each time action key is pressed, loop through the NPC array & see if distance is less than or equal to a talk distance you choose. Distance formula is: dist = math.sqrt((x1-x2)**2 + (y1-y2)**2) Remember, range function ends before last value so you can do: for iChar in range(0,iChars): #do stuff To determine if a player is Ally, Enemy, or NPC, maybe have a team variable (team=1 for ally, 0 for NPC, 2 for enemy -- it is best to use positive numbers in case you need them to reference an array, such as a team array that stores info about the team). Later, you could even use more numbers to make teams, for example, if you want two enemies to attack each other with AI, make one of them alignment=3.